package com.itheima.Demo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class DemoList的遍历 {
    public static void main(String[] args) {
        //创建集合;
        List<String> list = new ArrayList<>();
        list.add("张晗");
        list.add("拜清清");
        list.add("张梓墨");
        //遍历
        //迭代器
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String s = iterator.next();
            System.out.println(s);
        }
        System.out.println("==========================");
        //增强for
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("==========================");
        //普通for循环;
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }
}
